package com.mybatis.dao;

import com.mybatis.pojo.User;
import com.mybatis.util.mybatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

public class userdaoText {
    @Test
    public void test(){
        SqlSession sqlSession = mybatisUtil.getSqlSession();
        Mapper userdao = sqlSession.getMapper(Mapper.class);
        List<User> userList = userdao.getUserList();

        for (User user :userList){
            System.out.println(user);
        }

        sqlSession.close();
    }
    @Test
    public void  getUserById(){
        SqlSession sqlSession = mybatisUtil.getSqlSession();

        Mapper mapper =  sqlSession.getMapper(Mapper.class);
        User user = mapper.getUserId(1);
        System.out.println(user);
        sqlSession.close();


    }
    @Test
    public void addUser(){
        SqlSession sqlSession = mybatisUtil.getSqlSession();
        Mapper mapper =  sqlSession.getMapper(Mapper.class);
        int in=mapper.addUser(new User(6,"王五","123456"));
        if(in>0){
            System.out.println("插入数据成功");
        }
        sqlSession.commit();
        sqlSession.close();
    }
}
